package org.hhw.doc;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

/**
 * 对象与文档直接映射
 */
@Document(indexName = "test",type = "person") //test索引库 person类型的文档
public class PersonDoc {

    @Id //文档的id就是对象的id
    private Long id;
    //没有特殊要求不用@Field
    private Integer age;
    @Field(type = FieldType.Keyword)
    private String name; //zs
    @Field(type = FieldType.Text,analyzer = "ik_max_word"
            ,searchAnalyzer = "ik_max_word")
    private String intro; //zs is

    //关键字搜索，作用要name和intro字段
    //方案1:做组合查询 or 如果字段过多
    //方案2：虚拟字段all(所有需要做关键字搜索的值，中间通过空格分隔) zs +" "+ zs is .相当于一个字段代替了很多字段
    //模糊查询所有字段
    @Field(type =FieldType.Text,analyzer = "ik_max_word",searchAnalyzer = "ik_max_word")
    private String all; //name intro

    //进行拼接
    public String getAll() {
        return this.name+" "+this.intro;
    }


    public void setAll(String all) {
        this.all = all;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIntro() {
        return intro;
    }

    public void setIntro(String intro) {
        this.intro = intro;
    }

    public PersonDoc(Long id, Integer age, String name) {
        this.id = id;
        this.age = age;
        this.name = name;
    }

    @Override
    public String toString() {
        return "PersonDoc{" +
                "id=" + id +
                ", age=" + age +
                ", name='" + name + '\'' +
                '}';
    }

    public PersonDoc() {
    }
}
